<?php
// 建造者 生成器模式
// 将一个类的属性或者方法交给builder来构建
// director负责命令builder完成
interface Builder
{
	public function buildPartA();
	public function buildPartB();
}

class CarBuilder implements Builder
{
	public $car;

	public function __construct()
	{
		$this->car = new Car;
	}

	public function buildPartA()
	{

	}

	public function buildPartB()
	{

	}

	public function getResult()
	{
		return $this->car;
	}
}

class Car
{
	protected $partA;
	protected $partB;
	protected $partC;

}

interface Director
{
	public $myBuilder;

	public function startBuild()
	{
		$this->myBuilder->buildPartA();
		$this->myBuilder->buildPartB();
		return $this->myBuilder->getResult();
	}

	public function setBuilder(Builder $builder)
	{
		$this->myBuilder = $builder;
	}
}

$carBuilder = new CarBuilder;
$director = new Director;
$director->setBuilder($carBuilder);
$car = $director->startBuild();